Dart BigInt operator ~
Syntax & Examples


BigInt.operator ~ operator

The `~` operator performs bitwise negation on this BigInt.


Syntax of BigInt.operator ~

The syntax of BigInt.operator ~ operator is:

operator ~() → BigInt

This operator ~ operator of BigInt the bit-wise negate operator.



✐ Examples

1 Perform bitwise negation on positive BigInt

In this example,

  1. We define a positive BigInt num with a value of 5.
  2. We use the `~` operator to perform bitwise negation on num.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(5);
  BigInt result = ~num;
  print('Bitwise negation of 5: $result');
}

Output

Bitwise negation of 5: -6

2 Perform bitwise negation on negative BigInt

In this example,

  1. We define a negative BigInt num with a value of -5.
  2. We use the `~` operator to perform bitwise negation on num.
  3. We print the result to standard output.

Dart Program

void main() {
  BigInt num = BigInt.from(-5);
  BigInt result = ~num;
  print('Bitwise negation of -5: $result');
}

Output

Bitwise negation of -5: 4

Summary

In this Dart tutorial, we learned about operator ~ operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.